﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Configuration;

namespace BHair.Base
{
    public partial class frm会员级别 : Form
    {
        public frm会员级别()
        {
            InitializeComponent();
        }
        string constr = ConfigurationManager.ConnectionStrings["BHair.Properties.Settings.BHairDBConnectionString"].ConnectionString;
        private void frm会员级别_Load(object sender, EventArgs e)
        {
            SqlConnection conn = new SqlConnection(constr);
            conn.Open();
            string str = "SELECT [id] ,[级别] ,[积分额度],积分率,倍数 FROM [会员级别]";
            SqlDataAdapter sda = new SqlDataAdapter(str,conn);
            DataTable dt = new DataTable();
            sda.Fill(dt);
            dataGridView1.DataSource = dt;
            conn.Close();
        }
        public void jz()
        {
            SqlConnection conn = new SqlConnection(constr);
            conn.Open();
            string str = "SELECT [id] ,[级别] ,[积分额度],积分率,倍数 FROM [会员级别]";
            SqlDataAdapter sda = new SqlDataAdapter(str, conn);
            DataTable dt = new DataTable();
            sda.Fill(dt);
            dataGridView1.DataSource = dt;
            conn.Close();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            frm级别增加 zj = new frm级别增加();
            zj.ShowDialog();
            jz();
        }

        private void button3_Click(object sender, EventArgs e)
        {
            SqlConnection conn = new SqlConnection(constr);
            conn.Open();
            for (int i = 0; i < dataGridView1.Rows.Count; i++)
            {
                
                string sql =string.Format( " UPDATE[会员级别] SET[级别] = '{0}' ,[积分额度] ='{1}',[积分率] ='{2}',倍数='{3}' WHERE id ={4}", this.dataGridView1.CurrentRow.Cells[1].Value.ToString(), this.dataGridView1.CurrentRow.Cells[2].Value.ToString(), this.dataGridView1.CurrentRow.Cells[3].Value.ToString(), this.dataGridView1.CurrentRow.Cells[4].Value.ToString(), this.dataGridView1.CurrentRow.Cells[0].Value.ToString());
                SqlCommand comm = new SqlCommand(sql,conn);
                comm.ExecuteNonQuery();
                
            }
            MessageBox.Show("修改成功");
            conn.Close();
            jz();
        }
    }
}
